<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        <li>
                            房间编号：<input type="text" name="roomCode"/>
                        </li>


                        <li>
                            状态：<select name="status" th:with="type=${@dict.getType('order_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var orderStatus = [[${@dict.getType('order_status')}]];
    var prefix = ctx + "system/customer";

    $(function () {
        var options = {
            url: prefix + "/orders/list",
            modalName: "我的订单",
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'roomId',
                    title: '房间id',
                    sortable: true
                },
                {
                    field: 'roomCode',
                    title: '房间编号',
                    sortable: true
                },
                {
                    field: 'userId',
                    title: '用户id',
                    sortable: true
                },
                {
                    field: 'userName',
                    title: '用户姓名',
                    sortable: true
                },
                {
                    field: 'stopDay',
                    title: '入住天数',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '开单时间',
                    sortable: true
                },
                {
                    field: 'amount',
                    title: '金额',
                    sortable: true
                },
                {
                    field: 'status',
                    title: '状态',
                    sortable: true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderStatus, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.status === 1) {
                            var actions = [];
                            actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="cancel(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消</a>');
                            return actions.join('');
                        }
                    }
                }]
        };
        $.table.init(options);
    });

    function cancel(orderId) {
        $.modal.confirm("确认要取消预订吗？", function() {
            $.operate.post(prefix + "/cancel", { "orderId": orderId});
        })
    }
</script>
</body>
</html>